package com.lushu.chapitre1.graphics.containers
{
	import com.lushu.chapitre1.graphics.elements.MultiLayerElement;
	import com.lushu.graphics.core.SpriteEx;
	
	import flash.display.Bitmap;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;

	public class MultiLayerElementContainer extends SpriteEx
	{
		public function MultiLayerElementContainer(layeredElement : MultiLayerElement = null, width : int = 0, height : int = 0, align : String = "center")
		{
			_width = width;
			_height = height;
			_align = align;
			
			_layeredElement = layeredElement;
			_containingBitmap = new Bitmap();
			attachChild(_containingBitmap, 0, 0, "containingBitmap");
			
			_mainLoopTimer = new Timer(20, 0);
			_mainLoopTimer.addEventListener(TimerEvent.TIMER, onLoop);
			_mainLoopTimer.start();
		}
		
		private function onLoop(e : TimerEvent) : void
		{
			_containingBitmap.bitmapData = _layeredElement.view;
			if(_align == "center")
			{
				_layeredElement.x = 20;
				_layeredElement.y = 20;
				var position : Point = _layeredElement.position;
				_containingBitmap.x = (position.x)// + (_width  - _containingBitmap.width) >> 1 ;
				_containingBitmap.y = (position.y)// + (_height  - _containingBitmap.height) >> 1 ;
			}
		}
		
		// ------------------------------------------ //
		//											  //
		// 				 proprerties				  //
		//											  //
		// ------------------------------------------ //
		
		private var _layeredElement : MultiLayerElement;
		private var _containingBitmap : Bitmap;
		private var _mainLoopTimer : Timer;
		private var _width : int;
		private var _height : int;
		private var _align : String;
		
		
		// ------------------------------------------ //
		//											  //
		// 				   methods					  //
		//											  //
		// ------------------------------------------ //
		
		// ------------------------------------------ //
		//											  //
		// 				event handlers	  			  //
		//											  //
		// ------------------------------------------ //
	}
	
	
}